<?php
session_start();
include_once '../c/config.php';
$_SESSION['openid']=$_GET['openid'];
$state='';
if (isset($_GET['state'])){
    $state=$_GET['state'];
}
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
$sql="select id from users where openid='".$_SESSION['openid']."'  limit 0,1 ";
$query = $mysqli->query($sql);
if($query->num_rows>0){
    $sql="UPDATE `users` SET `lai` = '".$state."' WHERE openid='".$_SESSION['openid']."' ";
}else{
    $sql = "insert into users(openid,lai,createtime) values ('".$_SESSION['openid']."','".$state."','".date("Y-m-d H:i:s")."' )";
}
$mysqli->query($sql);

$sql = "insert into users_log(openid,lai,createtime) values ('".$_SESSION['openid']."','".$state."','".date("Y-m-d H:i:s")."' )";
$mysqli->query($sql);
header('Location: ../home.php');
exit;


//http://test-sweixinweb.hisense.com/interface/forward/init?state=mei94H5

?>